package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2024/2/19 09:11
 * @apiNote
 */

public class Test00447NumberOfBoomerangs {
    public static void main(String[] args) {
        int[][] points = {{0,0},{1,0},{2,0}};
        System.out.println(numberOfBoomerangs(points));
    }

    public static int numberOfBoomerangs(int[][] points) {
        int ans = 0;
        for(int[] p : points){
            Map<Integer,Integer> cnt = new HashMap<>();
            for(int[] q : points){
                int d = (p[0] - q[0]) * (p[0] - q[0]) + (p[1] - q[1]) * (p[1] - q[1]);
                cnt.put(d,cnt.getOrDefault(d,0) + 1);
            }
            for(Map.Entry<Integer,Integer> entry : cnt.entrySet()){
                int m =  entry.getValue();
                ans += m * (m - 1);
            }
        }
        return ans;
    }
}
